import request from '@/utils/request'
// import qs from 'qs'

// 系统升级

// 上传文件
export function upload (params) {
  var data = fromData(params)
  return request({
    url: '/update/upload',
    method: 'post',
    data
  })
}

// 获取系统版本信息
export function getUpdateInfo (params) {
  var data = fromData(params)
  return request({
    url: '/update/getUpdateInfo',
    method: 'post',
    data
  })
}

// 升级
export function getUpgrade (params) {
  var data = fromData(params)
  return request({
    url: '/update/upgrade',
    method: 'post',
    data
  })
}

// 系统升级--判断是否已上传
export function uploadExist (params) {
  var data = fromData(params)
  return request({
    url: '/update/uploadExist',
    method: 'post',
    data
  })
}

// 获取本地固件包信息
export function getFirmwareInfo (params) {
  var data = fromData(params)
  return request({
    url: '/update/getFirmwareInfo',
    method: 'post',
    data
  })
}

// 删除本地固件包信息
export function delFirmwareInfo (params) {
  var data = fromData(params)
  return request({
    url: '/update/delFirmwareInfo',
    method: 'post',
    data
  })
}

// 删除本地固件包信息
export function updateCheck (params) {
  var data = fromData(params)
  return request({
    url: '/update/check',
    method: 'post',
    data
  })
}

// 获取服务器订阅地
export function getFirmwareSubscribe (params) {
  var data = fromData(params)
  return request({
    url: '/update/getFirmwareSubscribe',
    method: 'post',
    data
  })
}

// 设置自动订阅服务器更新
export function setSubscribe (params) {
  var data = fromData(params)
  return request({
    url: '/update/setSubscribe',
    method: 'post',
    data
  })
}

// 立即拉取服务器更新
export function updateSubscribe (params) {
  var data = fromData(params)
  return request({
    url: '/update/updateSubscribe',
    method: 'post',
    data
  })
}

// 操作系统升级--上传文件
export function sysUpload (params) {
  var data = fromData(params)
  return request({
    url: '/update/sysUpload',
    method: 'post',
    data
  })
}

// 操作系统升级--验证固件包
export function sysCheck (params) {
  var data = fromData(params)
  return request({
    url: '/update/sysCheck',
    method: 'post',
    data
  })
}

// 操作系统升级--升级
export function sysUpgrade (params) {
  var data = fromData(params)
  return request({
    url: '/update/sysUpgrade',
    method: 'post',
    data
  })
}

// 操作系统升级--获取操作系统版本信息
export function getSysUpdateInfo (params) {
  var data = fromData(params)
  return request({
    url: '/update/getSysUpdateInfo',
    method: 'post',
    data
  })
}

// 操作系统升级--判断那是否上传
export function sysUploadExist (params) {
  var data = fromData(params)
  return request({
    url: '/update/sysUploadExist',
    method: 'post',
    data
  })
}

// 操作系统升级--取消正在上传的文件
export function uploadCancel (params) {
  var data = fromData(params)
  return request({
    url: '/update/uploadCancel',
    method: 'post',
    data
  })
}

// 操作系统升级--合并分卷文件
export function uploadMerge (params) {
  var data = fromData(params)
  return request({
    url: '/update/uploadMerge',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
